<template>
  <div class="dashboard-container">
    <div class="dashboard-text">name: {{ name }}</div>
    <!-- 顶部四个表随便写写反正写死 -->
    <div class="top">
      <el-card>
        <header>
          <span class="title">随便写写</span>
          <i class="el-icon-star-off title"></i>
        </header>
        <div id="maintop" ref="top"></div>
      </el-card>
      <el-card>
        <header>
          <span class="title">编程语言年内职位需求波动随便写写</span>
          <i class="el-icon-help title"></i>
        </header>
        <div id="chart-container" ref="topmind"></div>
      </el-card>
      <el-card>
        <header>
          <span class="title">平均分数统计随便写写</span>
          <i class="el-icon-help title"></i>
        </header>
        <div id="chart-container" ref="topRight"></div>
      </el-card>
      <el-card>
        <header>
          <span class="title">济南市今日温度随便写写</span>
          <i class="el-icon-help title"></i>
        </header>
        <div id="chart-container" ref="topLast"></div>
      </el-card>
    </div>
    <!-- 中部 -->
    <div class="bottom">
      <el-card>
        <header>
          <span class="title">前端与java学科试题走势图</span>
          <i class="el-icon-star-off title"></i>
        </header>
        <!-- @tab-click="handleClick" -->
        <el-tabs v-model="activeName">
          <el-tab-pane label="前端学科" name="first">
            <div id="bmain" ref="gop"></div>
          </el-tab-pane>
          <el-tab-pane label="Java学科" name="second">
            <div id="bmain" ref="bop"></div>
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
    <!-- 底部 -->
    <!-- <div class="bottom">
      <el-card>
        <header>
          <span class="title">搜索量对比图</span>
          <i class="el-icon-star-off title"></i>
        </header>
        <div id="main" ref="min"></div>
      </el-card>
    </div> -->
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import * as echarts from 'echarts'
import 'echarts-gl'
export default {
  // 组件名称
  name: 'Dashboard',
  // 局部注册的组件
  components: {},
  // 组件参数 接收来自父组件的数据
  props: {},
  // 组件状态值
  data() {
    return {
      activeName: 'second'
    }
  },
  // 计算属性
  computed: {
    ...mapGetters(['name'])
  },
  // 侦听器
  watch: {},
  // 以下是生命周期钩子   注：没用到的钩子请自行删除
  /**
   * 在实例初始化之后，组件属性计算之前，如data属性等
   */
  beforeCreate() {},
  /**
   * 组件实例创建完成，属性已绑定，但DOM还未生成，$ el属性还不存在
   */
  created() {},
  /**
   * 在挂载开始之前被调用：相关的 render 函数首次被调用。
   */
  beforeMount() {},
  /**
   * el 被新创建的 vm.$ el 替换，并挂载到实例上去之后调用该钩子。
   * 如果 root 实例挂载了一个文档内元素，当 mounted 被调用时 vm.$ el 也在文档内。
   */
  mounted() {
    // 前端学科
    const gop = echarts.init(this.$refs.gop)
    gop.resize()
    gop.setOption({
      title: {
        text: 'Temperature Change in the Coming Week'
      },
      xAxis: {
        type: 'category',
        boundaryGap: false
      },
      yAxis: {
        type: 'value',
        boundaryGap: [0, '30%']
      },

      visualMap: {
        type: 'piecewise',
        show: false,
        dimension: 0,
        seriesIndex: 0,
        pieces: [
          {
            gt: 1,
            lt: 3,
            color: 'rgba(0, 0, 180, 0.4)'
          },
          {
            gt: 5,
            lt: 7,
            color: 'rgba(0, 0, 180, 0.4)'
          }
        ]
      },
      series: [
        {
          type: 'line',
          smooth: 0.6,
          symbol: 'none',
          lineStyle: {
            color: '#5470C6',
            width: 5
          },
          markLine: {
            symbol: ['none', 'none'],
            label: { show: false },
            data: [{ xAxis: 1 }, { xAxis: 3 }, { xAxis: 5 }, { xAxis: 7 }]
          },
          areaStyle: {},
          data: [
            ['2019-10-10', 200],
            ['2019-10-11', 560],
            ['2019-10-12', 750],
            ['2019-10-13', 580],
            ['2019-10-14', 250],
            ['2019-10-15', 300],
            ['2019-10-16', 450],
            ['2019-10-17', 300],
            ['2019-10-18', 100]
          ]
        }
      ]
    })
    // java学科
    const bop = echarts.init(this.$refs.bop)
    bop.resize()
    bop.setOption({
      tooltip: {
        trigger: 'axis'
      },
      legend: {},
      toolbox: {
        show: true,
        feature: {
          dataZoom: {
            yAxisIndex: 'none'
          },
          dataView: { readOnly: false },
          magicType: { type: ['line', 'bar'] },
          restore: {},
          saveAsImage: {}
        }
      },
      xAxis: {
        type: 'category',
        boundaryGap: false,
        data: ['周1', '周2', '周3', '周4', '周5', '周6', '周7']
      },
      yAxis: {
        type: 'value',
        axisLabel: {
          formatter: '{value} °C'
        }
      },
      series: [
        {
          name: 'Highest',
          type: 'line',
          data: [10, 11, 13, 11, 12, 12, 9],
          markPoint: {
            data: [
              { type: 'max', name: 'Max' },
              { type: 'min', name: 'Min' }
            ]
          },
          markLine: {
            data: [{ type: 'average', name: 'Avg' }]
          }
        },
        {
          name: 'Lowest',
          type: 'line',
          data: [1, -2, 2, 5, 3, 2, 0],
          markPoint: {
            data: [{ name: '周最低', value: -2, xAxis: 1, yAxis: -1.5 }]
          },
          markLine: {
            data: [
              { type: 'average', name: 'Avg' },
              [
                {
                  symbol: 'none',
                  x: '90%',
                  yAxis: 'max'
                },
                {
                  symbol: 'circle',
                  label: {
                    position: 'start',
                    formatter: 'Max'
                  },
                  type: 'max',
                  name: '最高点'
                }
              ]
            ]
          }
        }
      ]
    })

    // 首个表假数据
    const top = echarts.init(this.$refs.top)
    top.resize()
    top.setOption({
      xAxis: {
        data: ['周一', '周二', '周三', '周四', '周五']
      },
      yAxis: {},
      series: [
        {
          type: 'bar',
          data: [23, 24, 18, 35, 18],
          barGap: '20%',
          barCategoryGap: '50%'
        },
        {
          type: 'bar',
          data: [12, 14, 9, 9, 11]
        }
      ]
    })
    // 第二个表数据
    const topmind = echarts.init(this.$refs.topmind)
    topmind.setOption({
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'line',
          lineStyle: {
            color: 'rgba(0,0,0,0.2)',
            width: 1,
            type: 'solid'
          }
        }
      },
      legend: {
        data: ['PHP', 'TY', 'JS', 'C', 'SY', 'DD']
      },
      singleAxis: {
        top: 40,
        bottom: 20,
        axisTick: {},
        axisLabel: {},
        type: 'time',
        axisPointer: {
          animation: true,
          label: {
            show: true
          }
        },
        splitLine: {
          show: true,
          lineStyle: {
            type: 'dashed',
            opacity: 0.2
          }
        }
      },
      series: [
        {
          type: 'themeRiver',
          emphasis: {
            itemStyle: {
              shadowBlur: 20,
              shadowColor: 'rgba(0, 0, 0, 0.8)'
            }
          },
          data: [
            ['2015/11/08', 10, 'PHP'],
            ['2015/11/09', 15, 'PHP'],
            ['2015/11/10', 35, 'PHP'],
            ['2015/11/11', 38, 'PHP'],
            ['2015/11/12', 22, 'PHP'],
            ['2015/11/13', 16, 'PHP'],
            ['2015/11/14', 7, 'PHP'],
            ['2015/11/15', 2, 'PHP'],
            ['2015/11/16', 17, 'PHP'],
            ['2015/11/17', 33, 'PHP'],
            ['2015/11/18', 40, 'PHP'],
            ['2015/11/19', 32, 'PHP'],
            ['2015/11/20', 26, 'PHP'],
            ['2015/11/21', 35, 'PHP'],
            ['2015/11/22', 40, 'PHP'],
            ['2015/11/23', 32, 'PHP'],
            ['2015/11/24', 26, 'PHP'],
            ['2015/11/25', 22, 'PHP'],
            ['2015/11/26', 16, 'PHP'],
            ['2015/11/27', 22, 'PHP'],
            ['2015/11/28', 10, 'PHP'],
            ['2015/11/08', 35, 'TS'],
            ['2015/11/09', 36, 'TS'],
            ['2015/11/10', 37, 'TS'],
            ['2015/11/11', 22, 'TS'],
            ['2015/11/12', 24, 'TS'],
            ['2015/11/13', 26, 'TS'],
            ['2015/11/14', 34, 'TS'],
            ['2015/11/15', 21, 'TS'],
            ['2015/11/16', 18, 'TS'],
            ['2015/11/17', 45, 'TS'],
            ['2015/11/18', 32, 'TS'],
            ['2015/11/19', 35, 'TS'],
            ['2015/11/20', 30, 'TS'],
            ['2015/11/21', 28, 'TS'],
            ['2015/11/22', 27, 'TS'],
            ['2015/11/23', 26, 'TS'],
            ['2015/11/24', 15, 'TS'],
            ['2015/11/25', 30, 'TS'],
            ['2015/11/26', 35, 'TS'],
            ['2015/11/27', 42, 'TS'],
            ['2015/11/28', 42, 'TS'],
            ['2015/11/08', 21, 'JS'],
            ['2015/11/09', 25, 'JS'],
            ['2015/11/10', 27, 'JS'],
            ['2015/11/11', 23, 'JS'],
            ['2015/11/12', 24, 'JS'],
            ['2015/11/13', 21, 'JS'],
            ['2015/11/14', 35, 'JS'],
            ['2015/11/15', 39, 'JS'],
            ['2015/11/16', 40, 'JS'],
            ['2015/11/17', 36, 'JS'],
            ['2015/11/18', 33, 'JS'],
            ['2015/11/19', 43, 'JS'],
            ['2015/11/20', 40, 'JS'],
            ['2015/11/21', 34, 'JS'],
            ['2015/11/22', 28, 'JS'],
            ['2015/11/23', 26, 'JS'],
            ['2015/11/24', 37, 'JS'],
            ['2015/11/25', 41, 'JS'],
            ['2015/11/26', 46, 'JS'],
            ['2015/11/27', 47, 'JS'],
            ['2015/11/28', 41, 'JS'],
            ['2015/11/08', 10, 'C'],
            ['2015/11/09', 15, 'C'],
            ['2015/11/10', 35, 'C'],
            ['2015/11/11', 38, 'C'],
            ['2015/11/12', 22, 'C'],
            ['2015/11/13', 16, 'C'],
            ['2015/11/14', 7, 'C'],
            ['2015/11/15', 2, 'C'],
            ['2015/11/16', 17, 'C'],
            ['2015/11/17', 33, 'C'],
            ['2015/11/18', 40, 'C'],
            ['2015/11/19', 32, 'C'],
            ['2015/11/20', 26, 'C'],
            ['2015/11/21', 35, 'C'],
            ['2015/11/22', 40, 'C'],
            ['2015/11/23', 32, 'C'],
            ['2015/11/24', 26, 'C'],
            ['2015/11/25', 22, 'C'],
            ['2015/11/26', 16, 'C'],
            ['2015/11/27', 22, 'C'],
            ['2015/11/28', 10, 'C'],
            ['2015/11/08', 10, 'SY'],
            ['2015/11/09', 15, 'SY'],
            ['2015/11/10', 35, 'SY'],
            ['2015/11/11', 38, 'SY'],
            ['2015/11/12', 22, 'SY'],
            ['2015/11/13', 16, 'SY'],
            ['2015/11/14', 7, 'SY'],
            ['2015/11/15', 2, 'SY'],
            ['2015/11/16', 17, 'SY'],
            ['2015/11/17', 33, 'SY'],
            ['2015/11/18', 40, 'SY'],
            ['2015/11/19', 32, 'SY'],
            ['2015/11/20', 26, 'SY'],
            ['2015/11/21', 35, 'SY'],
            ['2015/11/22', 4, 'SY'],
            ['2015/11/23', 32, 'SY'],
            ['2015/11/24', 26, 'SY'],
            ['2015/11/25', 22, 'SY'],
            ['2015/11/26', 16, 'SY'],
            ['2015/11/27', 22, 'SY'],
            ['2015/11/28', 10, 'SY'],
            ['2015/11/08', 10, 'DD'],
            ['2015/11/09', 15, 'DD'],
            ['2015/11/10', 35, 'DD'],
            ['2015/11/11', 38, 'DD'],
            ['2015/11/12', 22, 'DD'],
            ['2015/11/13', 16, 'DD'],
            ['2015/11/14', 7, 'DD'],
            ['2015/11/15', 2, 'DD'],
            ['2015/11/16', 17, 'DD'],
            ['2015/11/17', 33, 'DD'],
            ['2015/11/18', 4, 'DD'],
            ['2015/11/19', 32, 'DD'],
            ['2015/11/20', 26, 'DD'],
            ['2015/11/21', 35, 'DD'],
            ['2015/11/22', 40, 'DD'],
            ['2015/11/23', 32, 'DD'],
            ['2015/11/24', 26, 'DD'],
            ['2015/11/25', 22, 'DD'],
            ['2015/11/26', 16, 'DD'],
            ['2015/11/27', 22, 'DD'],
            ['2015/11/28', 10, 'DD']
          ]
        }
      ]
    })
    // 顶部右侧数据
    const topRight = echarts.init(this.$refs.topRight)
    topRight.resize()
    topRight.setOption({
      legend: {
        top: 'bottom'
      },
      series: [
        {
          name: 'Nightingale Chart',
          type: 'pie',
          radius: [5, 55],
          center: ['45%', '35%'],
          roseType: 'area',
          itemStyle: {
            borderRadius: 5
          },
          data: [
            { value: 40, name: '逻辑' },
            { value: 38, name: '基础' },
            { value: 32, name: '理论' },
            { value: 30, name: '日常' },
            { value: 28, name: '实战' },
            { value: 26, name: '模拟面试' }
          ]
        }
      ]
    })
    const topLast = echarts.init(this.$refs.topLast)
    topRight.resize()
    topLast.setOption({
      series: [
        {
          type: 'gauge',
          center: ['50%', '70%'],
          startAngle: 200,
          endAngle: -20,
          min: 0,
          max: 30,
          splitNumber: 12,
          itemStyle: {
            color: '#FFAB91'
          },
          progress: {
            show: true,
            width: 30
          },
          pointer: {
            show: false
          },
          axisLine: {
            lineStyle: {
              width: 30
            }
          },
          axisTick: {
            distance: -45,
            splitNumber: 5,
            lineStyle: {
              width: 2,
              color: '#999'
            }
          },
          splitLine: {
            distance: -52,
            length: 14,
            lineStyle: {
              width: 3,
              color: '#999'
            }
          },
          axisLabel: {
            distance: -20,
            color: '#999',
            fontSize: 20
          },
          anchor: {
            show: false
          },
          title: {
            show: false
          },
          detail: {
            valueAnimation: true,
            width: '60%',
            lineHeight: 10,
            borderRadius: 8,
            offsetCenter: [0, '-15%'],
            fontSize: 30,
            fontWeight: 'bolder',
            formatter: '{value} °C',
            color: 'inherit'
          },
          data: [
            {
              value: 20
            }
          ]
        },
        {
          type: 'gauge',
          center: ['10%', '60%'],
          startAngle: 200,
          endAngle: -20,
          min: 0,
          max: 60,
          itemStyle: {
            color: '#FD7347'
          },
          progress: {
            show: true,
            width: 8
          },
          pointer: {
            show: false
          },
          axisLine: {
            show: false
          },
          axisTick: {
            show: false
          },
          splitLine: {
            show: false
          },
          axisLabel: {
            show: false
          },
          detail: {
            show: false
          },
          data: [
            {
              value: 20
            }
          ]
        }
      ]
    })
  },
  /**
   * 数据更新时调用，发生在虚拟 DOM 重新渲染和打补丁之前。
   * 你可以在这个钩子中进一步地更改状态，这不会触发附加的重渲染过程。
   */
  beforeUpdate() {},
  /**
   * 由于数据更改导致的虚拟 DOM 重新渲染和打补丁，在这之后会调用该钩子。
   * 当这个钩子被调用时，组件 DOM 已经更新，所以你现在可以执行依赖于 DOM 的操作。
   */
  updated() {},
  /**
   * keep-alive 组件激活时调用。 仅针对keep-alive 组件有效
   */
  activated() {},
  /**
   * keep-alive 组件停用时调用。 仅针对keep-alive 组件有效
   */
  deactivated() {},
  /**
   * 实例销毁之前调用。在这一步，实例仍然完全可用。
   */
  beforeDestroy() {},
  /**
   * Vue 实例销毁后调用。调用后，Vue 实例指示的所有东西都会解绑定，
   * 所有的事件监听器会被移除，所有的子实例也会被销毁。
   */
  destroyed() {},
  // 组件方法
  methods: {
    // 获取试题列表
    // handleClick() {}
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<!--使用了scoped属性之后，父组件的style样式将不会渗透到子组件中，-->
<!--然而子组件的根节点元素会同时被设置了scoped的父css样式和设置了scoped的子css样式影响，-->
<!--这么设计的目的是父组件可以对子组件根元素进行布局。-->
<style lang="scss" scoped>
.bottom {
  height: 500px;
  margin-bottom: 20px;
  .el-card {
    margin-right: 10px;
    width: 100%;
    height: 100%;
  }
  .el-card__body {
    padding: 0;
  }

  #bmain,
  html,
  body {
    width: 100%;
  }
  #bmain {
    height: 430px;
  }
  #main,
  html,
  body {
    width: 100%;
  }
  #main {
    height: 460px;
  }
}
* {
  margin: 0;
  padding: 0;
}
.dashboard {
  &-container {
    margin: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}

.top {
  margin-top: 90px;
  display: flex;
  flex-wrap: nowrap;
  .el-card {
    margin-right: 10px;
    margin-bottom: 20px;
    width: 25%;
    height: 280px;
  }
  .el-card__body {
    padding: 0;
  }
  #chart-container,
  #maintop,
  html,
  body {
    width: 100%;
  }
  #chart-container {
    height: 240px;
  }
  #maintop {
    height: 260px;
  }
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 16px;
  .title {
    font-size: 14px;
    color: #ccc;
    span {
      text-align: left;
    }
    i {
      text-align: right;
    }
  }
}
.qianduan {
  width: 100%;
}
</style>
